package com.eastfair.datasync.service.impl;

import com.eastfair.datasync.dao.UserKafkaAccountMapper;
import com.eastfair.datasync.entity.UserKafkaAccount;
import com.eastfair.datasync.service.UserKafkaAccountService;
import com.eastfair.boot.service.SuperServiceImpl;
import com.eastfair.database.mybatis.conditions.Wraps;
import com.eastfair.database.mybatis.conditions.query.QueryWrap;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.eastfair.constant.BusinessConstant;
import com.eastfair.core.base.R;

import java.util.Collection;

//import com.baomidou.dynamic.datasource.annotation.DS;
import org.springframework.aop.framework.AopContext;
import com.eastfair.annotation.annotation.cache.Magic;
import com.eastfair.annotation.annotation.cache.Cache;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.commons.lang3.StringUtils;
//import com.baomidou.dynamic.datasource.annotation.DS;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;

import com.eastfair.datasync.vo.*;
import com.eastfair.datasync.dto.*;

/**
 * <p>
 * 业务实现类
 * 用户表
 * </p>
 *
 * @author ligang
 * @date 2023-03-29
 */
@Slf4j
@Service
//@DS("#thread.tenant")
public class UserKafkaAccountServiceImpl extends SuperServiceImpl<UserKafkaAccountMapper, UserKafkaAccount> implements UserKafkaAccountService {


    /**
     * 处理逻辑删除相关处理
     *
     * @param modelList 实体
     * @return 是否成功
     */
    @Override
    protected R<Boolean> handlerRemoveByIdsOfLogic(Collection<UserKafkaAccount> modelList) {
        modelList.stream().forEach(s -> {
            s.setIsDeleted(BusinessConstant.YES);
        });
        // TODO: 2021/10/29 这里需要操作其他业务，如清空角色等
        return R.successDef();
    }

    /**
     * 通用查询
     *
     * @param modelDTO DTO
     * @param ids      主键id集合
     * @return list
     */
    @Override
    public List<UserKafkaAccount> list(UserKafkaAccountDTO modelDTO, List<Long> ids) {
        return ((UserKafkaAccountService) AopContext.currentProxy()).listOfCache(modelDTO, ids);
    }


    /**
     * 缓存查询
     *
     * @param modelDTO DTO
     * @param ids      主键id集合
     * @return list
     */
    @Override
    @Cache(key = "",
            magic = @Magic(
                    key = "{" +
                            "{'headImg', #args[0]?.headImg}," +
                            "{'nickName', #args[0]?.nickName}," +
                            "{'name', #args[0]?.name}," +
                            "{'mobileCountryCode', #args[0]?.mobileCountryCode}," +
                            "{'gender', #args[0]?.gender}," +
                            "{'mobile', #args[0]?.mobile}," +
                            "{'password', #args[0]?.password}," +
                            "{'email', #args[0]?.email}," +
                            "{'status', #args[0]?.status}," +
                            "{'companyId', #args[0]?.companyId}," +
                            "{'exhibitorId', #args[0]?.exhibitorId}," +
                            "{'visitorId', #args[0]?.visitorId}," +
                            "{'isVisitor', #args[0]?.isVisitor}," +
                            "{'isSponsor', #args[0]?.isSponsor}," +
                            "{'isEmployee', #args[0]?.isEmployee}," +
                            "{'isActor', #args[0]?.isActor}," +
                            "{'isTourist', #args[0]?.isTourist}," +
                            "{'isEnabled', #args[0]?.isEnabled}," +
                            "{'idCard', #args[0]?.idCard}," +
                            "{'realName', #args[0]?.realName}," +
                            "{'isP', #args[0]?.isP}," +
                            "{'isPVenue', #args[0]?.isPVenue}," +
                            "{'isPCertificate', #args[0]?.isPCertificate}," +
                            "{'isPCompositeVenue', #args[0]?.isPCompositeVenue}," +
                            "{'isPCompositeCourt', #args[0]?.isPCompositeCourt}," +
                            "{'isPCompositeProducer', #args[0]?.isPCompositeProducer}," +
                            "{'isPCompositeTransport', #args[0]?.isPCompositeTransport}," +
                            "{'isPCompositeTrade', #args[0]?.isPCompositeTrade}," +
                            "{'isPCompositeMating', #args[0]?.isPCompositeMating}," +
                            "{'isPPay', #args[0]?.isPPay}," +
                            "{'isPExhibitorSelf', #args[0]?.isPExhibitorSelf}," +
                            "{'isPCateringapp', #args[0]?.isPCateringapp}," +
                            "{'isPCatering', #args[0]?.isPCatering}," +
                            "{'isPPortalOutVenue', #args[0]?.isPPortalOutVenue}," +
                            "{'isPPortalOutOperation', #args[0]?.isPPortalOutOperation}," +
                            "{'isPPortalInWork', #args[0]?.isPPortalInWork}," +
                            "{'isPPortalInWorkapp', #args[0]?.isPPortalInWorkapp}," +
                            "{'isPOperationCenter', #args[0]?.isPOperationCenter}," +
                            "{'isPVisitorFront', #args[0]?.isPVisitorFront}," +
                            "{'isPVisitorBack', #args[0]?.isPVisitorBack}," +
                            "{'matingId', #args[0]?.matingId}," +
                            "{'transportId', #args[0]?.transportId}," +
                            "{'courtId', #args[0]?.courtId}," +
                            "{'producerId', #args[0]?.producerId}," +
                            "{'isAdmin', #args[0]?.isAdmin}," +
                            "{'isSuperAdmin', #args[0]?.isSuperAdmin}," +
                            "{'iamUserId', #args[0]?.iamUserId}," +
                            "{'isPrimaryAccount', #args[0]?.isPrimaryAccount}," +
                            "{'id', #args[1]}" +
                            "}"))
    public List<UserKafkaAccount> listOfCache(UserKafkaAccountDTO modelDTO, List<Long> ids) {
        //查询
        UserKafkaAccount queryModel = new UserKafkaAccount();
        if (modelDTO != null) {
            BeanUtils.copyProperties(modelDTO, queryModel);
        }

        QueryWrap<UserKafkaAccount> wrapper = Wraps.q(queryModel);
        if (ids != null && !ids.isEmpty()) {
            wrapper.lambda().in(UserKafkaAccount::getId, ids);
        }
        //添加其他业务查询条件
        wrapper.lambda().eq(UserKafkaAccount::getIsDeleted, BusinessConstant.DELETE_NO);
        List<UserKafkaAccount> modelList = list(wrapper);
        return modelList;
    }


    /**
     * do转vo
     *
     * @param model model
     * @return modelVo
     */
    @Override
    public UserKafkaAccountVO doToVo(UserKafkaAccount model) {
        UserKafkaAccountVO modelVo = new UserKafkaAccountVO();
        BeanUtils.copyProperties(model, modelVo);
        modelVo.setId(model.getId());
        return modelVo;
    }

    /**
     * do转vo
     *
     * @param modelList modelList
     * @return list
     */
    @Override
    public List<UserKafkaAccountVO> doToVos(List<UserKafkaAccount> modelList) {
        if (modelList == null || modelList.isEmpty()) {
            return null;
        }
        List<UserKafkaAccountVO> result = new ArrayList<>();
        for (UserKafkaAccount model : modelList) {
            result.add(doToVo(model));
        }
        return result;
    }
}
